load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "gentbl_filegroup", "td_library")

package(
    # copybara:uncomment default_applicable_licenses = ["//stablehlo:license"],
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

# copybara:uncomment_begin
# license(
#     name = "license",
#     package_name = "stablehlo",
# )
# copybara:uncomment_end

exports_files([
    "LICENSE",
    # Export StablehloApi for MLIR-free portable API users.
    "stablehlo/integrations/python/StablehloApi.cpp",
    "stablehlo/integrations/python/StablehloApi.h",
])

filegroup(
    name = "stablehlo_ops_td_filegroup",
    srcs = glob(["stablehlo/dialect/*.td"]),
)

cc_library(
    name = "base",
    srcs = [
        "stablehlo/dialect/Base.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/Base.h",
    ],
    includes = ["."],
    deps = [
        ":base_attr_interfaces_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:BytecodeOpInterface",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "base_attr_interfaces_inc_gen",
    tbl_outs = [
        (
            ["-gen-attr-interface-decls"],
            "stablehlo/dialect/BaseAttrInterfaces.h.inc",
        ),
        (
            ["-gen-attr-interface-defs"],
            "stablehlo/dialect/BaseAttrInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/Base.td",
    deps = [":stablehlo_ops_td_files"],
)

td_library(
    name = "base_td_files",
    srcs = [
        "stablehlo/dialect/Base.td",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//mlir:InferTypeOpInterfaceTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:QuantizationOpsTdFiles",
    ],
)

cc_library(
    name = "broadcast_utils",
    srcs = [
        "stablehlo/dialect/BroadcastUtils.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/BroadcastUtils.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "check_ops_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "stablehlo/tests/CheckOps.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "stablehlo/tests/CheckOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/tests/CheckOps.td",
    deps = [
        ":check_ops_td_files",
    ],
)

td_library(
    name = "check_ops_td_files",
    srcs = [
        "stablehlo/tests/CheckOps.td",
    ],
    includes = ["."],
    deps = [
        ":base_td_files",
    ],
)

cc_library(
    name = "check_ops",
    srcs = [
        "stablehlo/tests/CheckOps.cpp",
    ],
    hdrs = [
        "stablehlo/tests/CheckOps.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":check_ops_inc_gen",
        ":reference_element",
        ":reference_errors",
        ":reference_numpy",
        ":reference_tensor",
        ":reference_types",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "chlo_attrs_inc_gen",
    tbl_outs = [
        (
            ["-gen-attrdef-decls"],
            "stablehlo/dialect/ChloAttrs.h.inc",
        ),
        (
            ["-gen-attrdef-defs"],
            "stablehlo/dialect/ChloAttrs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/ChloOps.td",
    deps = [
        ":chlo_ops_td_files",
    ],
)

CHLO_CAPI_SOURCES = [
    "stablehlo/integrations/c/ChloAttributes.cpp",
    "stablehlo/integrations/c/ChloDialect.cpp",
]

CHLO_CAPI_HEADERS = [
    "stablehlo/integrations/c/ChloAttributes.h",
    "stablehlo/integrations/c/ChloDialect.h",
]

cc_library(
    name = "chlo_capi",
    srcs = CHLO_CAPI_SOURCES,
    hdrs = CHLO_CAPI_HEADERS,
    deps = [
        ":chlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:CAPIIR",
    ],
)

# Header-only target, used when using the C API from a separate shared library.
cc_library(
    name = "chlo_capi_headers",
    hdrs = CHLO_CAPI_HEADERS,
    includes = ["."],
    deps = [
        "@llvm-project//mlir:CAPIIRHeaders",
    ],
)

# Alwayslink target, used when exporting the C API from a shared library.
cc_library(
    name = "chlo_capi_objects",
    srcs = CHLO_CAPI_SOURCES,
    hdrs = CHLO_CAPI_HEADERS,
    deps = [
        ":chlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:CAPIIRObjects",
    ],
    alwayslink = True,
)

gentbl_cc_library(
    name = "chlo_enums_inc_gen",
    tbl_outs = [
        (
            ["-gen-enum-decls"],
            "stablehlo/dialect/ChloEnums.h.inc",
        ),
        (
            ["-gen-enum-defs"],
            "stablehlo/dialect/ChloEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/ChloOps.td",
    deps = [
        ":chlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "chlo_ops_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "stablehlo/dialect/ChloOps.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "stablehlo/dialect/ChloOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/ChloOps.td",
    deps = [
        ":chlo_ops_td_files",
    ],
)

filegroup(
    name = "chlo_ops_py_files",
    srcs = [
        "stablehlo/integrations/python/mlir/dialects/chlo.py",
        ":chlo_ops_py_gen",
    ],
)

gentbl_filegroup(
    name = "chlo_ops_py_gen",
    tbl_outs = [
        (
            [
                "-gen-python-op-bindings",
                "-bind-dialect=chlo",
            ],
            "stablehlo/integrations/python/mlir/dialects/_chlo_ops_gen.py",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/integrations/python/mlir/dialects/ChloOps.td",
    deps = [
        ":chlo_ops_td_files",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

filegroup(
    name = "chlo_py_api_files",
    srcs = [
        "stablehlo/integrations/python/ChloModule.cpp",
    ],
)

td_library(
    name = "chlo_ops_td_files",
    srcs = [
        "stablehlo/dialect/ChloEnums.td",
        "stablehlo/dialect/ChloOps.td",
    ],
    includes = ["."],
    deps = [
        ":base_td_files",
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:ControlFlowInterfacesTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

cc_library(
    name = "chlo_ops",
    srcs = [
        "stablehlo/dialect/ChloBytecode.cpp",
        "stablehlo/dialect/ChloOps.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/ChloBytecode.h",
        "stablehlo/dialect/ChloOps.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":broadcast_utils",
        ":chlo_attrs_inc_gen",
        ":chlo_enums_inc_gen",
        ":chlo_ops_inc_gen",
        ":stablehlo_type_inference",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:BytecodeOpInterface",
        "@llvm-project//mlir:ComplexDialect",
        "@llvm-project//mlir:ControlFlowInterfaces",
        "@llvm-project//mlir:Dialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "chlo_rewriters_inc_gen",
    tbl_outs = [
        (
            ["--gen-rewriters"],
            "stablehlo/transforms/ChloDecompositionPatterns.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/transforms/ChloDecompositionPatterns.td",
    deps = [
        ":chlo_ops_td_files",
        ":stablehlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "stablehlo_legalize_deprecated_ops_inc_gen",
    tbl_outs = [
        (
            ["--gen-rewriters"],
            "stablehlo/transforms/StablehloLegalizeDeprecatedOpsPatterns.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/transforms/StablehloLegalizeDeprecatedOpsPatterns.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "vhlo_rewriters_inc_gen",
    tbl_outs = [
        (
            ["--gen-rewriters"],
            "stablehlo/transforms/VhloToVersionPatterns.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/transforms/VhloToVersionPatterns.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "stablehlo_create_compatibility_expander_inc_gen",
    tbl_outs = [
        (
            ["--gen-rewriters"],
            "stablehlo/transforms/StablehloCreateCompatibilityExpanderPatterns.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/transforms/StablehloCreateCompatibilityExpanderPatterns.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

cc_test(
    name = "example_add",
    srcs = [
        "examples/c++/ExampleAdd.cpp",
    ],
    deps = [
        ":reference_api",
        ":reference_configuration",
        ":stablehlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "interpreter_ops",
    srcs = [
        "stablehlo/reference/InterpreterOps.cpp",
    ],
    hdrs = [
        "stablehlo/reference/InterpreterOps.h",
    ],
    includes = ["."],
    deps = [
        ":interpreter_ops_inc_gen",
        ":reference_numpy",
        ":reference_ops",
        ":reference_process",
        ":reference_process_grid",
        ":reference_value",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "interpreter_ops_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "stablehlo/reference/InterpreterOps.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "stablehlo/reference/InterpreterOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/reference/InterpreterOps.td",
    deps = [
        ":interpreter_ops_td_files",
    ],
)

td_library(
    name = "interpreter_ops_td_files",
    srcs = [
        "stablehlo/reference/InterpreterOps.td",
    ],
    includes = ["."],
    deps = [
        ":base_td_files",
    ],
)

gentbl_cc_library(
    name = "interpreter_pass_inc_gen",
    strip_include_prefix = ".",
    tbl_outs = [
        (
            [
                "-gen-pass-decls",
                "-name=InterpreterTransforms",
            ],
            "stablehlo/reference/InterpreterPasses.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/reference/InterpreterPasses.td",
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

cc_library(
    name = "interpreter_passes",
    srcs = [
        "stablehlo/reference/InterpreterInstrumentWithProbe.cpp",
    ],
    hdrs = [
        "stablehlo/reference/InterpreterPasses.h",
    ],
    includes = ["."],
    deps = [
        ":interpreter_ops",
        ":interpreter_pass_inc_gen",
        ":stablehlo_ops",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TransformUtils",
    ],
)

gentbl_cc_library(
    name = "linalg_pass_inc_gen",
    strip_include_prefix = ".",
    tbl_outs = [
        (
            [
                "-gen-pass-decls",
                "-name=StablehloLinalgTransforms",
            ],
            "stablehlo/conversions/linalg/transforms/Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/conversions/linalg/transforms/Passes.td",
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

cc_library(
    name = "linalg_passes",
    srcs = [
        "stablehlo/conversions/linalg/transforms/LegalizeToLinalgUtils.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloLegalizeToLinalg.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToArith.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToLinalgConvolution.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToLinalgDotProduct.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToLinalgPointwise.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToLinalgRandom.cpp",
        "stablehlo/conversions/linalg/transforms/StablehloToLinalgReduce.cpp",
        "stablehlo/conversions/linalg/transforms/TypeConversion.cpp",
    ],
    hdrs = [
        "stablehlo/conversions/linalg/transforms/LegalizeToLinalgUtils.h",
        "stablehlo/conversions/linalg/transforms/MapStablehloToScalarOp.h",
        "stablehlo/conversions/linalg/transforms/Passes.h",
        "stablehlo/conversions/linalg/transforms/Rewriters.h",
        "stablehlo/conversions/linalg/transforms/TypeConversion.h",
    ],
    strip_include_prefix = ".",
    deps = [
        ":base",
        ":chlo_ops",
        ":linalg_pass_inc_gen",
        ":stablehlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:ArithUtils",
        "@llvm-project//mlir:BufferizationDialect",
        "@llvm-project//mlir:ComplexDialect",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:LinalgDialect",
        "@llvm-project//mlir:LinalgTransforms",
        "@llvm-project//mlir:LinalgUtils",
        "@llvm-project//mlir:MathDialect",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Rewrite",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:SparseTensorDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:VectorDialect",
    ],
)

cc_library(
    name = "reference_api",
    srcs = [
        "stablehlo/reference/Api.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Api.h",
    ],
    strip_include_prefix = ".",
    deps = [
        ":interpreter_ops",
        ":reference_configuration",
        ":reference_errors",
        ":reference_numpy",
        ":reference_ops",
        ":reference_process",
        ":reference_scope",
        ":reference_tensor",
        ":reference_value",
        ":register",
        ":stablehlo_passes",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_axes",
    srcs = [
        "stablehlo/reference/Axes.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Axes.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_configuration",
    srcs = [
        "stablehlo/reference/Configuration.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Configuration.h",
    ],
    strip_include_prefix = ".",
    deps = [
        ":reference_errors",
        ":reference_process",
        ":reference_scope",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_element",
    srcs = [
        "stablehlo/reference/Element.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Element.h",
    ],
    includes = ["."],
    deps = [
        ":reference_errors",
        ":reference_types",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_errors",
    srcs = [
        "stablehlo/reference/Errors.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Errors.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//llvm:Support",
    ],
)

cc_library(
    name = "reference_index",
    srcs = [
        "stablehlo/reference/Index.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Index.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_numpy",
    srcs = [
        "stablehlo/reference/NumPy.cpp",
    ],
    hdrs = [
        "stablehlo/reference/NumPy.h",
    ],
    strip_include_prefix = ".",
    deps = [
        ":reference_tensor",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_ops",
    srcs = [
        "stablehlo/reference/Ops.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Ops.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":reference_axes",
        ":reference_configuration",
        ":reference_element",
        ":reference_errors",
        ":reference_index",
        ":reference_process",
        ":reference_process_grid",
        ":reference_scope",
        ":reference_tensor",
        ":reference_token",
        ":reference_types",
        ":reference_value",
        ":stablehlo_ops",
        ":stablehlo_type_inference",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_process",
    srcs = [
        "stablehlo/reference/Process.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Process.h",
    ],
    includes = ["."],
    deps = [
        ":reference_process_grid",
        ":reference_tensor",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_process_grid",
    srcs = [
        "stablehlo/reference/ProcessGrid.cpp",
    ],
    hdrs = [
        "stablehlo/reference/ProcessGrid.h",
    ],
    includes = ["."],
    deps = [
        ":reference_tensor",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_scope",
    srcs = [
        "stablehlo/reference/Scope.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Scope.h",
    ],
    includes = ["."],
    deps = [
        ":reference_tensor",
        ":reference_token",
        ":reference_value",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_tensor",
    srcs = [
        "stablehlo/reference/Tensor.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Tensor.h",
    ],
    includes = ["."],
    deps = [
        ":reference_axes",
        ":reference_element",
        ":reference_errors",
        ":reference_index",
        ":reference_types",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_token",
    srcs = [
        "stablehlo/reference/Token.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Token.h",
    ],
    includes = ["."],
    deps = [
        ":stablehlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_types",
    srcs = [
        "stablehlo/reference/Types.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Types.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "reference_value",
    srcs = [
        "stablehlo/reference/Value.cpp",
    ],
    hdrs = [
        "stablehlo/reference/Value.h",
    ],
    includes = ["."],
    deps = [
        ":reference_errors",
        ":reference_tensor",
        ":reference_token",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "register",
    srcs = [
        "stablehlo/dialect/Register.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/Register.h",
    ],
    deps = [
        ":chlo_ops",
        ":stablehlo_ops",
        ":vhlo_ops",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:SparseTensorDialect",
    ],
)

cc_library(
    name = "stablehlo_assembly_format",
    srcs = [
        "stablehlo/dialect/AssemblyFormat.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/AssemblyFormat.h",
    ],
    deps = [
        ":base",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "stablehlo_attrs_inc_gen",
    tbl_outs = [
        (
            ["-gen-attrdef-decls"],
            "stablehlo/dialect/StablehloAttrs.h.inc",
        ),
        (
            ["-gen-attrdef-defs"],
            "stablehlo/dialect/StablehloAttrs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/StablehloOps.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

STABLEHLO_CAPI_SOURCES = [
    "stablehlo/integrations/c/StablehloAttributes.cpp",
    "stablehlo/integrations/c/StablehloDialect.cpp",
    "stablehlo/integrations/c/StablehloPasses.cpp",
    "stablehlo/integrations/c/StablehloApi.cpp",
    "stablehlo/integrations/c/StablehloTypes.cpp",
]

STABLEHLO_CAPI_HEADERS = [
    "stablehlo/integrations/c/StablehloAttributes.h",
    "stablehlo/integrations/c/StablehloDialect.h",
    "stablehlo/integrations/c/StablehloPasses.h",
    "stablehlo/integrations/c/StablehloApi.h",
    "stablehlo/integrations/c/StablehloTypes.h",
]

cc_library(
    name = "stablehlo_capi",
    srcs = STABLEHLO_CAPI_SOURCES,
    hdrs = STABLEHLO_CAPI_HEADERS,
    deps = [
        ":reference_api",
        ":reference_configuration",
        ":stablehlo_ops",
        ":stablehlo_passes",
        ":stablehlo_portable_api",
        ":stablehlo_serialization",
        ":version",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:CAPIIR",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

# Header-only target, used when using the C API from a separate shared library.
cc_library(
    name = "stablehlo_capi_headers",
    hdrs = STABLEHLO_CAPI_HEADERS,
    includes = ["."],
    deps = [
        "@llvm-project//mlir:CAPIIRHeaders",
    ],
)

# Alwayslink target, used when exporting the C API from a shared library.
cc_library(
    name = "stablehlo_capi_objects",
    srcs = STABLEHLO_CAPI_SOURCES,
    hdrs = STABLEHLO_CAPI_HEADERS,
    deps = [
        ":reference_api",
        ":reference_configuration",
        ":stablehlo_ops",
        ":stablehlo_passes",
        ":stablehlo_portable_api",
        ":stablehlo_serialization",
        ":version",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:CAPIIRObjects",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
    alwayslink = True,
)

gentbl_cc_library(
    name = "stablehlo_enums_inc_gen",
    tbl_outs = [
        (
            ["-gen-enum-decls"],
            "stablehlo/dialect/StablehloEnums.h.inc",
        ),
        (
            ["-gen-enum-defs"],
            "stablehlo/dialect/StablehloEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/StablehloOps.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "stablehlo_types_inc_gen",
    tbl_outs = [
        (
            [
                "-gen-typedef-decls",
                "--typedefs-dialect=stablehlo",
            ],
            "stablehlo/dialect/StablehloTypeDefs.h.inc",
        ),
        (
            [
                "-gen-typedef-defs",
                "--typedefs-dialect=stablehlo",
            ],
            "stablehlo/dialect/StablehloTypeDefs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/StablehloOps.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "stablehlo_ops_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "stablehlo/dialect/StablehloOps.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "stablehlo/dialect/StablehloOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/StablehloOps.td",
    deps = [
        ":stablehlo_ops_td_files",
    ],
)

filegroup(
    name = "stablehlo_ops_py_files",
    srcs = [
        "stablehlo/integrations/python/mlir/dialects/stablehlo.py",
        ":stablehlo_ops_py_gen",
    ],
)

gentbl_filegroup(
    name = "stablehlo_ops_py_gen",
    tbl_outs = [
        (
            [
                "-gen-python-op-bindings",
                "-bind-dialect=stablehlo",
            ],
            "stablehlo/integrations/python/mlir/dialects/_stablehlo_ops_gen.py",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/integrations/python/mlir/dialects/StablehloOps.td",
    deps = [
        ":stablehlo_ops_td_files",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

filegroup(
    name = "stablehlo_py_api_files",
    srcs = [
        "stablehlo/integrations/python/StablehloApi.cpp",
        "stablehlo/integrations/python/StablehloApi.h",
        "stablehlo/integrations/python/StablehloModule.cpp",
    ],
)

td_library(
    name = "stablehlo_ops_td_files",
    srcs = [
        "stablehlo/dialect/Base.td",
        "stablehlo/dialect/StablehloAttrs.td",
        "stablehlo/dialect/StablehloEnums.td",
        "stablehlo/dialect/StablehloOps.td",
        "stablehlo/dialect/StablehloTypes.td",
        "stablehlo/transforms/ChloDecompositionPatternsMath.td",
    ],
    includes = ["."],
    deps = [
        ":base_td_files",
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:ShapeOpsTdFiles",
    ],
)

gentbl_cc_library(
    name = "stablehlo_pass_inc_gen",
    strip_include_prefix = ".",
    tbl_outs = [
        (
            [
                "-gen-pass-decls",
            ],
            "stablehlo/transforms/Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/transforms/Passes.td",
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

cc_library(
    name = "stablehlo_passes",
    srcs = [
        "stablehlo/transforms/ChloLegalizeToStablehlo.cpp",
        "stablehlo/transforms/PassPipelines.cpp",
        "stablehlo/transforms/PassUtils.cpp",
        "stablehlo/transforms/ShapeLegalizeToStablehlo.cpp",
        "stablehlo/transforms/StablehloAggressiveFolder.cpp",
        "stablehlo/transforms/StablehloAggressiveSimplification.cpp",
        "stablehlo/transforms/StablehloCanonicalizeDynamism.cpp",
        "stablehlo/transforms/StablehloConvertToSignless.cpp",
        "stablehlo/transforms/StablehloCreateCompatibilityExpander.cpp",
        "stablehlo/transforms/StablehloLegalizeCompositeToCall.cpp",
        "stablehlo/transforms/StablehloLegalizeDeprecatedOps.cpp",
        "stablehlo/transforms/StablehloLegalizeQDQToQuantizedOp.cpp",
        "stablehlo/transforms/StablehloLegalizeQuantToMath.cpp",
        "stablehlo/transforms/StablehloLegalizeQuantizedOpToQDQ.cpp",
        "stablehlo/transforms/StablehloLegalizeToVhlo.cpp",
        "stablehlo/transforms/StablehloRefineArguments.cpp",
        "stablehlo/transforms/StablehloRefineShapes.cpp",
        "stablehlo/transforms/VhloLegalizeToStablehlo.cpp",
        "stablehlo/transforms/VhloToVersion.cpp",
    ],
    hdrs = [
        "stablehlo/transforms/MapStablehloToVhlo.h",
        "stablehlo/transforms/PassUtils.h",
        "stablehlo/transforms/Passes.h",
        "stablehlo/transforms/StablehloRefineShapes.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":broadcast_utils",
        ":chlo_ops",
        ":chlo_rewriters_inc_gen",
        ":linalg_passes",
        ":stablehlo_create_compatibility_expander_inc_gen",
        ":stablehlo_legalize_deprecated_ops_inc_gen",
        ":stablehlo_ops",
        ":stablehlo_ops_inc_gen",
        ":stablehlo_pass_inc_gen",
        ":stablehlo_type_inference",
        ":version",
        ":vhlo_ops",
        ":vhlo_rewriters_inc_gen",
        ":vhlo_types",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:AsmParser",
        "@llvm-project//mlir:CommonFolders",
        "@llvm-project//mlir:ComplexDialect",
        "@llvm-project//mlir:DialectUtils",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FuncTransforms",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:ReconcileUnrealizedCasts",
        "@llvm-project//mlir:Rewrite",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

cc_library(
    name = "stablehlo_portable_api",
    srcs = [
        "stablehlo/api/PortableApi.cpp",
    ],
    hdrs = [
        "stablehlo/api/PortableApi.h",
    ],
    includes = ["."],
    deps = [
        ":register",
        ":stablehlo_serialization",
        ":version",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:BytecodeWriter",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "stablehlo_serialization",
    srcs = [
        "stablehlo/dialect/Serialization.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/Serialization.h",
    ],
    includes = ["."],
    deps = [
        ":stablehlo_passes",
        ":version",
        ":vhlo_ops",
        "@llvm-project//mlir:BytecodeWriter",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "stablehlo_type_inference",
    srcs = [
        "stablehlo/dialect/TypeInference.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/TypeInference.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":stablehlo_assembly_format",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Support",
    ],
)

cc_library(
    name = "stablehlo_ops",
    srcs = [
        "stablehlo/dialect/StablehloBytecode.cpp",
        "stablehlo/dialect/StablehloOps.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/StablehloBytecode.h",
        "stablehlo/dialect/StablehloOps.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":stablehlo_assembly_format",
        ":stablehlo_attrs_inc_gen",
        ":stablehlo_enums_inc_gen",
        ":stablehlo_ops_inc_gen",
        ":stablehlo_type_inference",
        ":stablehlo_types_inc_gen",
        ":version",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:BytecodeOpInterface",
        "@llvm-project//mlir:ComplexDialect",
        "@llvm-project//mlir:DataLayoutInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:SparseTensorDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
    ],
)

cc_binary(
    name = "stablehlo-translate",
    srcs = [
        "stablehlo/tools/StablehloTranslateMain.cpp",
    ],
    deps = [
        ":check_ops",
        ":interpreter_ops",
        ":reference_api",
        ":reference_configuration",
        ":reference_errors",
        ":reference_numpy",
        ":reference_ops",
        ":reference_process",
        ":reference_process_grid",
        ":reference_scope",
        ":reference_tensor",
        ":reference_value",
        ":register",
        ":stablehlo_ops",
        ":stablehlo_serialization",
        ":test_utils",
        ":version",
        ":vhlo_ops",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AllPassesAndDialects",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:Transforms",
        "@llvm-project//mlir:TranslateLib",
    ],
)

cc_binary(
    name = "stablehlo-opt",
    srcs = [
        "stablehlo/tools/StablehloOptMain.cpp",
    ],
    deps = [
        ":check_ops",
        ":interpreter_ops",
        ":interpreter_passes",
        ":linalg_passes",
        ":register",
        ":stablehlo_passes",
        ":test_utils",
        ":tosa_passes",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AllExtensions",
        "@llvm-project//mlir:AllPassesAndDialects",
        "@llvm-project//mlir:MlirOptLib",
        "@llvm-project//mlir:TosaDialect",
    ],
)

glob_lit_tests(
    name = "all_tests",
    data = [":test_data"],
    driver = "@llvm-project//mlir:run_lit.sh",
    exclude = [
        # TODO(#268): Fix lit checks with floating-point ops having
        # implementation defined precision.
        "stablehlo/tests/interpret_rsqrt.mlir",
        "stablehlo/tests/interpret_sqrt.mlir",
        "stablehlo/tests/interpret_tanh.mlir",
    ],
    test_file_exts = ["mlir"],
)

filegroup(
    name = "test_data",
    testonly = True,
    data = [
        ":stablehlo-opt",
        ":stablehlo-translate",
        "@llvm-project//llvm:FileCheck",
        "@llvm-project//llvm:not",
    ],
)

gentbl_cc_library(
    name = "test_utils_inc_gen",
    tbl_outs = [
        (
            [
                "-gen-pass-decls",
                "-name=HloTest",
            ],
            "stablehlo/tests/TestUtils.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/tests/TestUtils.td",
    deps = [
        ":test_utils_td_files",
    ],
)

td_library(
    name = "test_utils_td_files",
    srcs = [
        "stablehlo/tests/TestUtils.td",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)

cc_library(
    name = "test_utils",
    srcs = [
        "stablehlo/tests/TestUtils.cpp",
    ],
    hdrs = [
        "stablehlo/tests/TestUtils.h",
    ],
    includes = ["."],
    deps = [
        ":test_utils_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InferTypeOpInterface",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Rewrite",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:SideEffectInterfaces",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TransformUtils",
    ],
)

gentbl_cc_library(
    name = "tosa_pass_inc_gen",
    strip_include_prefix = ".",
    tbl_outs = [
        (
            [
                "-gen-pass-decls",
                "-name=StablehloTOSATransforms",
            ],
            "stablehlo/conversions/tosa/transforms/Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/conversions/tosa/transforms/Passes.td",
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

cc_library(
    name = "tosa_passes",
    srcs = [
        "stablehlo/conversions/tosa/transforms/StablehloLegalizeToTosa.cpp",
        "stablehlo/conversions/tosa/transforms/StablehloPrepareForTosa.cpp",
        "stablehlo/conversions/tosa/transforms/StablehloQuantLegalizeToTosaRescale.cpp",
        "stablehlo/conversions/tosa/transforms/TosaRescaleLegalizeToStablehlo.cpp",
    ],
    hdrs = [
        "stablehlo/conversions/tosa/transforms/Passes.h",
    ],
    includes = ["."],
    deps = [
        ":stablehlo_ops",
        ":tosa_pass_inc_gen",
        ":tosa_pdll_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:PDLDialect",
        "@llvm-project//mlir:PDLInterpDialect",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:Rewrite",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TosaDialect",
        "@llvm-project//mlir:TransformUtils",
    ],
)

gentbl_cc_library(
    name = "tosa_pdll_inc_gen",
    strip_include_prefix = ".",
    tbl_outs = [
        (
            ["-x=cpp"],
            "stablehlo/conversions/tosa/transforms/StablehloLegalizeToTosa.pdll.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-pdll",
    td_file = "stablehlo/conversions/tosa/transforms/StablehloLegalizeToTosa.pdll",
    deps = [
        ":stablehlo_ops_td_files",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:TosaDialectTdFiles",
    ],
)

cc_library(
    name = "version",
    srcs = [
        "stablehlo/dialect/Version.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/Version.h",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "vhlo_attr_interfaces_inc_gen",
    tbl_outs = [
        (
            ["-gen-attr-interface-decls"],
            "stablehlo/dialect/VhloAttrInterfaces.h.inc",
        ),
        (
            ["-gen-attr-interface-defs"],
            "stablehlo/dialect/VhloAttrInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloAttrs.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "vhlo_attrs_inc_gen",
    tbl_outs = [
        (
            ["-gen-attrdef-decls"],
            "stablehlo/dialect/VhloAttrs.h.inc",
        ),
        (
            ["-gen-attrdef-defs"],
            "stablehlo/dialect/VhloAttrs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloOps.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

VHLO_CAPI_SOURCES = [
    "stablehlo/integrations/c/VhloDialect.cpp",
]

VHLO_CAPI_HEADERS = [
    "stablehlo/integrations/c/VhloDialect.h",
]

cc_library(
    name = "vhlo_capi",
    srcs = VHLO_CAPI_SOURCES,
    hdrs = VHLO_CAPI_HEADERS,
    deps = [
        ":vhlo_ops",
        "@llvm-project//mlir:CAPIIR",
    ],
)

# Header-only target, used when using the C API from a separate shared library.
cc_library(
    name = "vhlo_capi_headers",
    hdrs = VHLO_CAPI_HEADERS,
    includes = ["."],
    deps = [
        "@llvm-project//mlir:CAPIIRHeaders",
    ],
)

# Alwayslink target, used when exporting the C API from a shared library.
cc_library(
    name = "vhlo_capi_objects",
    srcs = VHLO_CAPI_SOURCES,
    hdrs = VHLO_CAPI_HEADERS,
    deps = [
        ":vhlo_ops",
        "@llvm-project//mlir:CAPIIRObjects",
    ],
    alwayslink = True,
)

gentbl_cc_library(
    name = "vhlo_enums_inc_gen",
    tbl_outs = [
        (
            ["-gen-enum-decls"],
            "stablehlo/dialect/VhloEnums.h.inc",
        ),
        (
            ["-gen-enum-defs"],
            "stablehlo/dialect/VhloEnums.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloEnums.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "vhlo_op_interfaces_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-interface-decls"],
            "stablehlo/dialect/VhloOpInterfaces.h.inc",
        ),
        (
            ["-gen-op-interface-defs"],
            "stablehlo/dialect/VhloOpInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloOps.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

cc_library(
    name = "vhlo_ops",
    srcs = [
        "stablehlo/dialect/VhloBytecode.cpp",
        "stablehlo/dialect/VhloOps.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/VhloBytecode.h",
        "stablehlo/dialect/VhloOps.h",
    ],
    includes = ["."],
    deps = [
        ":base",
        ":stablehlo_assembly_format",
        ":version",
        ":vhlo_attr_interfaces_inc_gen",
        ":vhlo_attrs_inc_gen",
        ":vhlo_enums_inc_gen",
        ":vhlo_op_interfaces_inc_gen",
        ":vhlo_ops_inc_gen",
        ":vhlo_types",
        ":vhlo_types_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:BytecodeOpInterface",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:Support",
    ],
)

gentbl_cc_library(
    name = "vhlo_ops_inc_gen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "stablehlo/dialect/VhloOps.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "stablehlo/dialect/VhloOps.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloOps.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

filegroup(
    name = "vhlo_ops_py_files",
    srcs = [
        "stablehlo/integrations/python/mlir/dialects/vhlo.py",
        ":vhlo_ops_py_gen",
    ],
)

gentbl_filegroup(
    name = "vhlo_ops_py_gen",
    tbl_outs = [
        (
            [
                "-gen-python-op-bindings",
                "-bind-dialect=vhlo",
            ],
            "stablehlo/integrations/python/mlir/dialects/_vhlo_ops_gen.py",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/integrations/python/mlir/dialects/VhloOps.td",
    deps = [
        ":vhlo_ops_td_files",
        "@llvm-project//mlir:OpBaseTdFiles",
    ],
)

td_library(
    name = "vhlo_ops_td_files",
    srcs = [
        "stablehlo/dialect/VhloAttrs.td",
        "stablehlo/dialect/VhloBase.td",
        "stablehlo/dialect/VhloDialect.td",
        "stablehlo/dialect/VhloEnums.td",
        "stablehlo/dialect/VhloOps.td",
        "stablehlo/dialect/VhloTypes.td",
    ],
    includes = ["."],
    deps = [
        "@llvm-project//mlir:BuiltinDialectTdFiles",
        "@llvm-project//mlir:OpBaseTdFiles",
        "@llvm-project//mlir:ShapeOpsTdFiles",
    ],
)

cc_library(
    name = "vhlo_types",
    srcs = [
        "stablehlo/dialect/VhloTypes.cpp",
    ],
    hdrs = [
        "stablehlo/dialect/VhloTypes.h",
    ],
    includes = ["."],
    deps = [
        ":stablehlo_assembly_format",
        ":version",
        ":vhlo_type_interfaces_inc_gen",
        ":vhlo_types_inc_gen",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:QuantOps",
        "@llvm-project//mlir:ShapeDialect",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TransformUtils",
    ],
)

gentbl_cc_library(
    name = "vhlo_type_interfaces_inc_gen",
    tbl_outs = [
        (
            ["-gen-type-interface-decls"],
            "stablehlo/dialect/VhloTypeInterfaces.h.inc",
        ),
        (
            ["-gen-type-interface-defs"],
            "stablehlo/dialect/VhloTypeInterfaces.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloTypes.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)

gentbl_cc_library(
    name = "vhlo_types_inc_gen",
    tbl_outs = [
        (
            ["-gen-typedef-decls"],
            "stablehlo/dialect/VhloTypeDefs.h.inc",
        ),
        (
            ["-gen-typedef-defs"],
            "stablehlo/dialect/VhloTypeDefs.cpp.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "stablehlo/dialect/VhloOps.td",
    deps = [
        ":vhlo_ops_td_files",
    ],
)
